package org.jeecg.modules.jxc.inventorymanagement.commodityloss.controller;

import io.swagger.annotations.Api;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.jxc.homepage.service.IJxcGoodsService;
import org.jeecg.modules.jxc.inventorymanagement.commodityloss.entity.JxcDamageList;
import org.jeecg.modules.jxc.inventorymanagement.commodityloss.service.IJxcDamageListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description: 报损报溢查询
 * @company: yaorange
 * @author: Mr.Sun
 * @version: 1.0
 * @create: 2021-12-22 18:55:04
 */
@Api(tags = "jxc_stock_limit")
@RestController
@RequestMapping("/damageOrOverflowGoods")
@Slf4j
public class JxcDamageOrOverflowQueryController {

    @Autowired
    private IJxcDamageListService jxcDamageListService;

    /**
     * 请求URL：http://localhost:8080/jeecg-boot/damageOrOverflowGoods/list
     * 请求参数：String  sTime（开始时间）, String  eTime（结束时间）
     * 请求方式：POST
     * 返回值类型：JSON
     */
    @PostMapping("/list/{sTime}/{eTime}/{type}")
    public ResponseEntity<Map<String,Object>> queryDamageOrOverflowList(@PathVariable String sTime, @PathVariable String eTime, @PathVariable Integer type){
//    public ResponseEntity<List<JxcDamageList>> queryDamageOrOverflowList(@PathVariable String sTime, @PathVariable String eTime, @PathVariable Integer type){
        try {
//            Map<String,Object> damageOrOverflowList = jxcDamageListService.findDamageOrOverflowList(sTime, eTime, type);
            List<Map<String,Object>> damageOrOverflowList = jxcDamageListService.findDamageOrOverflowList(sTime, eTime, type);
//            for (Map.Entry<String,Object> entry : damageOrOverflowList.entrySet())
//                System.out.println(entry.getKey()+"==========="+entry.getValue());
            HashMap<String, Object> stringObjectHashMap = new HashMap<>();
            stringObjectHashMap.put("success",true);
            stringObjectHashMap.put("rows",damageOrOverflowList);
            return ResponseEntity.ok(stringObjectHashMap);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseEntity.badRequest().build();
        }
    }
    /**
     *
     */
    /**
    * @author: Mr.Sun
    * @description:
     * 请求URL：http://localhost:8080/jeecg-boot/damageOrOverflowGoods/goodsList
     * 请求参数：Integer damageListId（报损单Id）
     * 请求方式：POST
     * 返回值类型：JSON
     * 返回值：Map<String,Object>
    * @param id
    * @param type：单据类型
    * @return java.util.Map<java.lang.String,java.lang.Object>
    * @exception
    */
    @PostMapping("/goodsList/{id}/{type}")
    public ResponseEntity<Map<String,Object>> queryDamageOrOverflowGoodsList(@PathVariable Integer id,@PathVariable Integer type){
        try {
        List<Map<String,Object>> damageOrOverflowList = jxcDamageListService.findDamageOrOverflowGoodsList(id,type);
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("success",true);
        stringObjectHashMap.put("rows",damageOrOverflowList);
        return ResponseEntity.ok(stringObjectHashMap);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseEntity.badRequest().build();
        }
    }
}
